package main

import (
	"fmt"
	"math"
)

func main() {
	loanAmount := 450000.0    // 贷款本金
	annualInterestRate := 3.8 // 年利率
	loanTermInYears := 30.0   // 还款年限
	monthlyPayment := calculateEMI(loanAmount, annualInterestRate, loanTermInYears)

	fmt.Printf("每月还款额：%.2f\n", monthlyPayment)
}

func calculateEMI(loanAmount float64, annualInterestRate float64, loanTermInYears float64) float64 {
	monthlyInterestRate := annualInterestRate / 12 / 100
	numberOfPayments := loanTermInYears * 12

	emi := loanAmount * (monthlyInterestRate * math.Pow(1+monthlyInterestRate, numberOfPayments)) /
		(math.Pow(1+monthlyInterestRate, numberOfPayments) - 1)

	return emi
}
